package com.hzhr.iot.user.dao;

import com.hzhr.iot.user.dao.mapper.custom.ActionEntityCustomMapper;
import com.hzhr.iot.user.dao.mapper.generator.ActionEntityMapper;
import com.hzhr.iot.user.entity.ActionEntity;
import com.hzhr.iot.user.entity.ext.ActionEntityExt;
import com.hzhr.iot.user.queryModel.custom.ActionCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class ActionDao {
    @Autowired
    ActionEntityMapper actionEntityMapper;
    @Autowired
    ActionEntityCustomMapper actionEntityCustomMapper;

    public int insert(ActionEntity record) {
        if (record == null) return 0;
        int changeCount = actionEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(ActionCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = actionEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(ActionEntity record) {
        if (record == null) return 0;
        int changeCount = actionEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(ActionCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = actionEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public ActionEntity selectEntity(ActionCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ActionEntityExt> extList = actionEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ActionEntity> selectEntityList(ActionCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ActionEntityExt> extList = actionEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<ActionEntity> entityList = new ArrayList<>();
        for (ActionEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public ActionEntityExt selectExt(ActionCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ActionEntityExt> extList = actionEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ActionEntityExt> selectExtList(ActionCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ActionEntityExt> extList = actionEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public ActionEntity selectEntity1(ActionCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ActionEntityExt> extList = actionEntityCustomMapper.selectExt1(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ActionEntity> selectEntityList1(ActionCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ActionEntityExt> extList = actionEntityCustomMapper.selectExt1(queryModel);
        if (extList == null) return null;
        List<ActionEntity> entityList = new ArrayList<>();
        for (ActionEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public ActionEntityExt selectExt1(ActionCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ActionEntityExt> extList = actionEntityCustomMapper.selectExt1(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ActionEntityExt> selectExtList1(ActionCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ActionEntityExt> extList = actionEntityCustomMapper.selectExt1(queryModel);
        return extList;
    }

    public int selectCount(ActionCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = actionEntityCustomMapper.selectCount(queryModel);
        return count;
    }
    public int selectCount1(ActionCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = actionEntityCustomMapper.selectCount1(queryModel);
        return count;
    }
}
